<?php

namespace app\index\controller\traffic;

use app\index\logic\traffic\ShipLogic;
use app\common\service\Util;
use think\facade\Request;


class Ship
{
    /**
     * 获取航线信息
     * @return void
     */
    public function getShipLine()
    {
        $param = Request::param();
        $shipLogic = new ShipLogic();
        $lineData = $shipLogic->getShipLine($param);

        if (empty($lineData)) {
            return Util::ajaxReturn(0, '未查询到路线', []);
        }

        return Util::ajaxReturn(1, 'OK', (array)$lineData);
    }

    /**
     * 获取航班信息
     * @return void
     */
    public function getShipFlight()
    {
        $param = Request::param();
        $shipLogic = new ShipLogic();
        $flightData = $shipLogic->getShipFlight($param);

        return Util::ajaxReturn(1, 'OK', (array)$flightData);
    }

    /**
     * 获取可改签的航班信息
     * @return void
     */
    public function getChangeableShipFlights()
    {
        $param = Request::param();
        // 验证必要参数
        if (empty($param['orderId']) || empty($param['date'])) {
            return Util::ajaxReturn(0, '缺少必要参数', []);
        }

        $shipLogic = new ShipLogic();
        $changeableFlights = $shipLogic->getChangeableShipFlights($param);

        if (empty($changeableFlights)) {
            return Util::ajaxReturn(0, '未查询到可改签的航班', []);
        }

        return Util::ajaxReturn(1, 'OK', (array)$changeableFlights);
    }
}
